//
//  ZHTableViewCell.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/3/17.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

enum ZHTabGroup {
    case `default`
    case  group
    case  multiple
}


class ZHTableViewCell: TableRowView {
    
    static let identifier = NSUserInterfaceItemIdentifier.init("ZHTableViewCell")
    
    var type:ZHTabGroup = .group {
        didSet {
            var title_left:CGFloat = 0
            var lineView_isHadden:Bool = false
            var textColor:NSColor = NSColor.clear
            
            switch type {
            case .default:
                title_left = 20
                lineView_isHadden = true
                textColor = color_gray(210)
            case .group:
                title_left = 20
                lineView_isHadden = true
                textColor = color_gray(160)
            case .multiple:
                title_left = 26
                lineView_isHadden = true
                textColor = color_gray(210)
            }
            
            self.stitle.snp.updateConstraints { (make) in
                make.left.equalTo(title_left)
            }
            self.stitle.textColor = textColor
            self.lineView.isHidden = lineView_isHadden
            
        }
    }
    
    var multipleSelect:Bool = false {
        didSet {
            self.selectImageV.isHidden = !multipleSelect
        }
    }
    
    
    convenience init(identifier:NSUserInterfaceItemIdentifier) {
        self.init()
        self.setupUI()
    }
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    convenience init(type:ZHTabGroup,identifier:NSUserInterfaceItemIdentifier) {
        self.init()
        self.identifier = identifier
        self.setupUI()
        self.type = type
    }
    
    func setupUI()  {
        
        self.focusRingType = .none

        self.addSubview(selectImageV)
        selectImageV.snp.makeConstraints { (make) in
            make.width.height.equalTo(12)
            make.left.equalTo(5)
            make.centerY.equalToSuperview()
        }
        
        self.addSubview(stitle)
        stitle.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview()
            make.height.equalTo(14)
            make.centerY.equalToSuperview()
        }
        
        self.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.centerX.width.equalToSuperview()
            make.bottom.equalToSuperview()
        }
    }
    
    func setBottomLine(isHidden:Bool=false) {
        self.lineView.isHidden = isHidden
    }
    
    
    lazy var lineView: NSView = {
        let view = NSView()
        view.wantsLayer = true
        view.layer?.backgroundColor = color_gray(160).withAlphaComponent(1).cgColor
        view.isHidden = true
        return view
    }()
    
    lazy var stitle: NSLabel = {
        let lab = NSLabel.label(title: "标题", textColor: color_gray(210), font: NSFont.systemFont(ofSize: 12))
        return lab
    }()
    
    lazy var selectImageV: NSImageView = {
        let imageV = NSImageView.init(image: NSImage.image(name:"icon_meeting_checkmark")!)
        imageV.isHidden = true
        return imageV
    }()
    
}
